﻿using System;
using System.Drawing;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using SmartWarehouse.Common;

/// <summary>
/// Summary description for SwBasePage
/// </summary>
public class SwBasePage:Page
{
    public SwBasePage()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    protected override void OnLoad(EventArgs e)  //Page_Load
    {
        if (UserName == string.Empty)
        {
            this.Response.Redirect("~/Login.aspx");
        }
        else
        {
            base.OnLoad(e);
        }
    }



    protected void ShowMessage(SwMessage message)
    {
        Label lblMsg = (this.Master.FindControl("lblMasterPageErrorMessage") as Label);
        if (message.MessageType == SwMessageType.Error)
        {
            lblMsg.ForeColor = Color.Red;
        }
        else if (message.MessageType == SwMessageType.Warnning)
        {
            lblMsg.ForeColor = Color.Yellow;
        }
        else
        {
            lblMsg.ForeColor = Color.Blue;
        }
        lblMsg.Text = message.MessageText;
    }
    protected void ClearMessage()
    {
        Label lblMsg = (this.Master.FindControl("lblMasterPageErrorMessage") as Label);
        lblMsg.ForeColor = Color.Blue;
        lblMsg.Text = string.Empty;
    }

    protected string UserName
    {
        get
        {
            if (this.Session["UserName"] == null)
                return string.Empty;
            else
                return this.Session["UserName"] as string;
        }
        set
        {
            this.Session["UserName"] = value;
        }
    }
}
